package com.demo;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.JwtBuilder;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.Date;

@SpringBootTest
public class Myjjwt {
    @Test
    public void login(){
        //将需要加密的数据传入builder
        JwtBuilder builder = Jwts.builder().setSubject("管理员").setId("1").setIssuedAt(new Date()).signWith(SignatureAlgorithm.HS256,"niubi");
        builder.claim("username","shabi").claim("password","123");
        String token = builder.compact();
        Claims clamis = Jwts.parser().setSigningKey("niubi").parseClaimsJws(token).getBody();
        System.out.println(clamis.getSubject());
    }
}
